package com.xuexiang.xqrcode;

import android.app.Activity;
import android.graphics.Bitmap;
import android.hardware.Camera;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import com.google.zxing.Result;
import com.xuexiang.xqrcode.camera.CameraManager;
import com.xuexiang.xqrcode.logs.QCLog;
import com.xuexiang.xqrcode.ui.CaptureActivity;
import com.xuexiang.xqrcode.ui.CaptureFragment;
import com.xuexiang.xqrcode.util.QRCodeAnalyzeUtils;
import com.xuexiang.xqrcode.util.QRCodeProduceUtils;
import java.util.List;

/* loaded from: classes2.dex */
public class XQRCode {
    public static final String ACTION_DEFAULT_CAPTURE = "com.xuexiang.xqrcode.ui.captureactivity";
    public static final String KEY_IS_REPEATED = "key_is_repeated";
    public static final String KEY_LAYOUT_ID = "key_layout_id";
    public static final String KEY_SCAN_INTERVAL = "key_scan_interval";
    public static final String RESULT_DATA = "result_data";
    public static final int RESULT_FAILED = 2;
    public static final int RESULT_SUCCESS = 1;
    public static final String RESULT_TYPE = "result_type";
    public static long sAutoFocusInterval = 1500;

    public static void debug(boolean z) {
        QCLog.debug(z);
    }

    public static void debug(String str) {
        QCLog.debug(str);
    }

    public static void setAutoFocusInterval(long j) {
        sAutoFocusInterval = j;
    }

    public static long getAutoFocusInterval() {
        return sAutoFocusInterval;
    }

    public static void startScan(Fragment fragment, int i) {
        CaptureActivity.start(fragment, i, R.style.XQRCodeTheme);
    }

    public static void startScan(Fragment fragment, int i, int i2) {
        CaptureActivity.start(fragment, i, i2);
    }

    public static void startScan(Activity activity, int i) {
        CaptureActivity.start(activity, i, R.style.XQRCodeTheme);
    }

    public static void startScan(Activity activity, int i, int i2) {
        CaptureActivity.start(activity, i, i2);
    }

    public static CaptureFragment getCaptureFragment(int i) {
        return CaptureFragment.newInstance(i);
    }

    public static CaptureFragment getCaptureFragment(int i, boolean z, long j) {
        return CaptureFragment.newInstance(i, z, j);
    }

    public static void setFragmentArgs(CaptureFragment captureFragment, int i) {
        setFragmentArgs(captureFragment, i, false, 0L);
    }

    public static void setFragmentArgs(CaptureFragment captureFragment, int i, boolean z, long j) {
        if (captureFragment == null || i == -1) {
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putInt(KEY_LAYOUT_ID, i);
        bundle.putBoolean(KEY_IS_REPEATED, z);
        bundle.putLong(KEY_SCAN_INTERVAL, j);
        captureFragment.setArguments(bundle);
    }

    public static void analyzeQRCode(String str, QRCodeAnalyzeUtils.AnalyzeCallback analyzeCallback) {
        QRCodeAnalyzeUtils.analyze(str, analyzeCallback);
    }

    public static String analyzeQRCode(String str) {
        return QRCodeAnalyzeUtils.analyze(str);
    }

    public static Result getAnalyzeQRCodeResult(String str) {
        return QRCodeAnalyzeUtils.getAnalyzeQRCodeResult(str);
    }

    public static Bitmap createQRCodeWithLogo(String str, int i, int i2, Bitmap bitmap) {
        return QRCodeProduceUtils.create(str, i, i2, bitmap);
    }

    public static Bitmap createQRCodeWithLogo(String str, Bitmap bitmap) {
        return QRCodeProduceUtils.create(str, 400, 400, bitmap);
    }

    public static QRCodeProduceUtils.Builder newQRCodeBuilder(String str) {
        return QRCodeProduceUtils.newBuilder(str);
    }

    public static void switchFlashLight(boolean z) throws RuntimeException {
        if (z) {
            enableFlashLight();
        } else {
            disableFlashLight();
        }
    }

    public static void disableFlashLight() {
        Camera.Parameters parameters;
        Camera camera = CameraManager.get().getCamera();
        if (camera == null || (parameters = camera.getParameters()) == null) {
            return;
        }
        parameters.setFlashMode("off");
        camera.setParameters(parameters);
    }

    public static void enableFlashLight() {
        Camera.Parameters parameters;
        List<String> supportedFlashModes;
        Camera camera = CameraManager.get().getCamera();
        if (camera == null || (parameters = camera.getParameters()) == null || (supportedFlashModes = parameters.getSupportedFlashModes()) == null) {
            return;
        }
        if (supportedFlashModes.contains("torch")) {
            parameters.setFlashMode("torch");
        } else if (supportedFlashModes.contains("on")) {
            parameters.setFlashMode("on");
        }
        camera.setParameters(parameters);
    }

    public static boolean isFlashLightOpen() {
        String flashMode = getFlashMode();
        if (flashMode == null || flashMode.length() <= 0) {
            return false;
        }
        return flashMode.equals("torch") || flashMode.equals("on");
    }

    private static String getFlashMode() {
        Camera camera = CameraManager.get().getCamera();
        if (camera != null) {
            return camera.getParameters().getFlashMode();
        }
        return null;
    }
}
